package com.doit.day05

object _01_偏函数 {
  def main(args: Array[String]): Unit = {

    val list: List[Any] = List(1, "zss", 2, 'c', true)
    //需求：将里面整数类型都乘以10输出，其他的都不要了

    val list1: List[Any] = list.filter((a: Any) => {
      a.isInstanceOf[Int]
    })

    list1.map((a:Any)=>{
      val i: Int = a.asInstanceOf[Int]
      i * 10
    }).foreach(println)

    //PartialFunction

    val pf: PartialFunction[Any, Int] = new PartialFunction[Any, Int] {
      //这个方法就类似于filter
      override def isDefinedAt(x: Any) = x.isInstanceOf[Int]

      //这个方法就类似于map
      override def apply(v1: Any) = v1.asInstanceOf[Int] * 10
    }


    val ints: List[Int] = list.collect(pf)
    ints.foreach(println)

  }
}
